/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import bentity.beLineaLog;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author renzo
 */
public class daoLog {

    public int registrarLog(int idUsuario, String cargo, String mensaje) throws Exception{
        String sql = "INSERT INTO LOG (id_Usuario, transaccion, fecha_hora, cargo) VALUES (?, ?, CURRENT_TIMESTAMP, ?)";
        Connection conn = daoHelper.dameConexion();
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setInt(1, idUsuario);
        ps.setString(2, mensaje);
        ps.setString(3, cargo);
        ps.executeUpdate();
        ps.close();
        conn.close();
        return daoHelper.TRANSACCION_EXITOSA;
    }

    public ArrayList<beLineaLog> queryAllLogs() throws Exception{
        String sql = "SELECT * FROM LOG";
        Connection conn = daoHelper.dameConexion();
        PreparedStatement ps = conn.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        ArrayList<beLineaLog> logs = new ArrayList<beLineaLog>();
        beLineaLog linLog = null;
        while(rs.next()){
            linLog = new beLineaLog();
            linLog.setIdLog(rs.getLong(1));
            linLog.setIdUsuario(rs.getInt(2));
            linLog.setTransaccion(rs.getString(3));
            linLog.setFecha(rs.getTimestamp(4));
            linLog.setCargo(rs.getString(5));
            logs.add(linLog);
        }
        rs.close();
        ps.close();
        conn.close();
        return logs;
    }

}
